package com.sh.rbac.core.sensitive.enums;

import cn.hutool.core.util.DesensitizedUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.function.Function;

/**
 * @author wb
 * @since 2025-11-06
 */

@Getter
@AllArgsConstructor
public enum SensitiveStrategy {

    /**
     * 用户id
     */
    USER_ID(s -> String.valueOf(DesensitizedUtil.userId())),

    /**
     * 中文姓名
     */
    CHINESE_NAME(DesensitizedUtil::chineseName),

    /**
     * 身份证号码
     */
    ID_CARD(s -> String.valueOf(DesensitizedUtil.idCardNum(s, 3, 4))),

    /**
     * 固定电话
     */
    FIXED_PHONE(DesensitizedUtil::fixedPhone),

    /**
     * 手机号码
     */
    MOBILE_PHONE(DesensitizedUtil::mobilePhone),

    /**
     * 地址
     */
    ADDRESS(s -> String.valueOf(DesensitizedUtil.address(s, 8))),

    /**
     * 电子邮件
     */
    EMAIL(DesensitizedUtil::email),

    /**
     * 密码
     */
    PASSWORD(DesensitizedUtil::password),

    /**
     * 银行卡
     */
    BANK_CARD(DesensitizedUtil::bankCard),

    /**
     * 车牌号
     */
    CAR_LICENSE(DesensitizedUtil::carLicense),

    /**
     * 密钥
     */
    KEY(s -> {
        if (s != null && s.length() > 8) {
            return s.substring(0, 4) + "****" + s.substring(s.length() - 4);
        } else {
            return "****";
        }
    });


    private final Function<String, String> sensitive;
}
